﻿workspace "GameEngine" -- 解决方案名称
    architecture "x64" -- 编译平台 只编64位(x86,x86_64,ARM)

    configurations 
    {
        "Debug",
        "Release",
        "Dist"
    }

-- 临时变量
-- 详细的所有支持的tokens可参考 [https://github.com/premake/premake-core/wiki/Tokens]
outputdir = "%{cfg.buildcfg}-%{cfg.system}-%{cfg.architecture}" -- 定义输出目录
includeDir = {}
includeDir["GLFW"] = "%{prj.name}/ThirdParty/GLFW/include"
includeDir["Glad"] = "%{prj.name}/ThirdParty/Glad/include"
includeDir["ImGui"] = "%{prj.name}/ThirdParty/imgui"
includeDir["glm"] = "%{prj.name}/ThirdParty/glm"
includeDir["stb_image"] = "%{prj.name}/ThirdParty/stb_image"

include "GameEngine/ThirdParty/GLFW"
include "GameEngine/ThirdParty/Glad"
include "GameEngine/ThirdParty/imgui"

project "GameEngine" -- 项目名称
    location "GameEngine" -- 相对路径
    kind "SharedLib" -- 表明该项目是dll动态库
    language "c++"
    cppdialect "c++17"
    staticruntime "off"

    targetdir ("bin/" .. outputdir .. "/%{prj.name}") -- 输出目录
    objdir ("bin-int/" .. outputdir .. "/%{prj.name}") -- 中间临时文件的目录

    pchheader "pch.h"
    pchsource "%{prj.name}/src/pch.cpp"

    files -- 该项目的文件
    {
        "%{prj.name}/src/**.h",
        "%{prj.name}/src/**.cpp",
        "%{prj.name}/ThirdParty/stb_image/**.h",
        "%{prj.name}/ThirdParty/stb_image/**.cpp",
        "%{prj.name}/ThirdParty/glm/glm/**.hpp",
        "%{prj.name}/ThirdParty/glm/glm/**.inl"
    }

	defines
	{
        "_CRT_SECURE_NO_WARNINGS"
	}

    includedirs -- 附加包含目录
    {
        "%{prj.name}/src",
        "%{prj.name}/ThirdParty/spdlog/include",
        "%{includeDir.GLFW}",
        "%{includeDir.Glad}",
        "%{includeDir.ImGui}",
        "%{includeDir.glm}",
        "%{includeDir.stb_image}"
    }

    links
    {
        "GLFW",
        "Glad",
        "ImGui",
        "opengl32.lib"
    }

    filter "system:windows" -- windows平台的配置
        -- staticruntime "on"
        systemversion "latest"

        defines -- 预编译宏
        {
            "PLATFORM_WINDOWS",
            "BUILD_DLL",
        }

        postbuildcommands -- build后的自定义命令
        {
            ("{COPY} %{cfg.buildtarget.relpath} ../bin/" .. outputdir .. "/GameEditor") -- 自动拷贝引擎dll库到GameEditor目录
        }

    filter "configurations:Debug"
        defines "DEBUG"
        runtime "Debug"
        -- buildoptions "/MDd"
        symbols "on"

    filter "configurations:Release"
        defines "RELEASE"
        runtime "Release"
        -- buildoptions "/MD"
        optimize "on"

    filter "configurations:Dist"
        defines "DIST"
        runtime "Release"
        -- buildoptions "/MD"
        optimize "on"

project "GameEditor"
    location "GameEditor"
    kind "ConsoleApp"
    language "c++"
    cppdialect "c++17"
	staticruntime "off"

    targetdir ("bin/" .. outputdir .. "/%{prj.name}")
    objdir ("bin-int/" .. outputdir .. "/%{prj.name}")

    files
    {
        "%{prj.name}/src/**.h",
        "%{prj.name}/src/**.cpp"
    }

    includedirs
    {
        "GameEngine/ThirdParty/spdlog/include",
        "GameEngine/src",
        "GameEngine/ThirdParty/glm"
    }

    -- 链接子项目
    links
    {
        "GameEngine"
    }

    filter "system:windows"
		cppdialect "c++17"
        -- staticruntime "on"
        systemversion "latest"

        defines
        {
            "PLATFORM_WINDOWS",
        }

    filter "configurations:Debug"
        defines "DEBUG"
        runtime "Debug"
        -- buildoptions "/MDd"
        symbols "on"

    filter "configurations:Release"
        defines "RELEASE"
        runtime "Release"
        -- buildoptions "/MD"
        optimize "on"

    filter "configurations:Dist"
        defines "DIST"
        runtime "Release"
        -- buildoptions "/MD"
        optimize "on"
